﻿// FovTestDlg.cpp: 实现文件
//

#include "pch.h"
#include "ProjectAA.h"
#include "FovTestDlg.h"
#include "afxdialogex.h"


// CFovTestDlg 对话框

IMPLEMENT_DYNAMIC(CFovTestDlg, CDialogEx)

CFovTestDlg::CFovTestDlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_DIALOG_FOV, pParent)
	, OpenFov(FALSE)
	, BaseAngle0(0)
	, BaceAngle1(0)
	, AddAngle0(0)
	, AddAngle1(0)
	, FovBin0(0)
	, FovBin1(0)
	, FovBin2(0)
	, FovBin3(0)
	, PosPer0(0)
	, PosPer1(0)
	, PosW0(0)
	, PosW1(0)
	, PosH0(0)
	, PosH1(0)
	, SpecH0(0)
	, SpecH1(0)
	, SpecV0(0)
	, SpecV1(0)
	, Display(FALSE)
{

}

CFovTestDlg::~CFovTestDlg()
{
}

void CFovTestDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Check(pDX, IDC_CHECK1, OpenFov);
	DDX_Text(pDX, IDC_EDIT1, BaseAngle0);
	DDX_Text(pDX, IDC_EDIT12, BaceAngle1);
	DDX_Text(pDX, IDC_EDIT2, AddAngle0);
	DDX_Text(pDX, IDC_EDIT13, AddAngle1);
	DDX_Text(pDX, IDC_EDIT4, FovBin0);
	DDX_Text(pDX, IDC_EDIT6, FovBin1);
	DDX_Text(pDX, IDC_EDIT14, FovBin2);
	DDX_Text(pDX, IDC_EDIT15, FovBin3);
	DDX_Text(pDX, IDC_EDIT7, PosPer0);
	DDX_Text(pDX, IDC_EDIT16, PosPer1);
	DDX_Text(pDX, IDC_EDIT8, PosW0);
	DDX_Text(pDX, IDC_EDIT17, PosW1);
	DDX_Text(pDX, IDC_EDIT9, PosH0);
	DDX_Text(pDX, IDC_EDIT18, PosH1);
	DDX_Text(pDX, IDC_EDIT10, SpecH0);
	DDX_Text(pDX, IDC_EDIT11, SpecH1);
	DDX_Text(pDX, IDC_EDIT19, SpecV0);
	DDX_Text(pDX, IDC_EDIT20, SpecV1);
	DDX_Check(pDX, IDC_CHECK5, Display);
	DDX_Control(pDX, IDC_COMBO2, DisplayCnt);
}


BEGIN_MESSAGE_MAP(CFovTestDlg, CDialogEx)
	ON_BN_CLICKED(IDC_BUTTON1, &CFovTestDlg::OnBnClickedButton1)
	ON_BN_CLICKED(IDC_CHECK5, &CFovTestDlg::OnBnClickedCheck5)
	ON_CBN_SELCHANGE(IDC_COMBO2, &CFovTestDlg::OnCbnSelchangeCombo2)
END_MESSAGE_MAP()


// CFovTestDlg 消息处理程序


BOOL CFovTestDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	ReadConfigIni();

	gSystemMgr.m_ptrFOVSettingDlg = this;
	return TRUE;
}


void CFovTestDlg::OnCancel()
{
	gSystemMgr.m_bFovDisplayFlag = 0;

	CDialogEx::OnCancel();
}

void CFovTestDlg::ReadConfigIni()
{
	OpenFov = gSystemMgr.m_nFovTestFlag;
	BaseAngle0 = gSystemMgr.m_dBsaicAngle;
	BaceAngle1 = gSystemMgr.m_dBsaicAngle2;
	AddAngle0 = gSystemMgr.m_dAddAngle;
	AddAngle1 = gSystemMgr.m_dAddAngle2;
	FovBin0 = gSystemMgr.m_nFovBin[0];
	FovBin1 = gSystemMgr.m_nFovBin[1];
	FovBin2 = gSystemMgr.m_nFovBin[2];
	FovBin3 = gSystemMgr.m_nFovBin[3];
	PosPer0 = gSystemMgr.m_nPosPer[0];
	PosPer1 = gSystemMgr.m_nPosPer[1];
	PosW0 = gSystemMgr.m_nPosW[0];
	PosW1 = gSystemMgr.m_nPosW[1];
	PosH0 = gSystemMgr.m_nPosH[0];
	PosH1 = gSystemMgr.m_nPosH[1];
	SpecH0 = gSystemMgr.m_nSpecAngleH[0];
	SpecH1 = gSystemMgr.m_nSpecAngleH[1];
	SpecV0 = gSystemMgr.m_nSpecAngleV[0];
	SpecV1 = gSystemMgr.m_nSpecAngleV[1];

	UpdateData(FALSE);
}

void CFovTestDlg::SaveValueToConfig()
{
	UpdateData(TRUE);

	gSystemMgr.m_nFovTestFlag = OpenFov;
	gSystemMgr.m_dBsaicAngle = BaseAngle0;
	gSystemMgr.m_dBsaicAngle2 = BaceAngle1;
	gSystemMgr.m_dAddAngle = AddAngle0;
	gSystemMgr.m_dAddAngle2 = AddAngle1;
	gSystemMgr.m_nFovBin[0] = FovBin0;
	gSystemMgr.m_nFovBin[1] = FovBin1;
	gSystemMgr.m_nFovBin[2] = FovBin2;
	gSystemMgr.m_nFovBin[3] = FovBin3;
	gSystemMgr.m_nPosPer[0] = PosPer0;
	gSystemMgr.m_nPosPer[1] = PosPer1;
	gSystemMgr.m_nPosW[0] = PosW0;
	gSystemMgr.m_nPosW[1] = PosW1;
	gSystemMgr.m_nPosH[0] = PosH0;
	gSystemMgr.m_nPosH[1] = PosH1;
	gSystemMgr.m_nSpecAngleH[0] = SpecH0;
	gSystemMgr.m_nSpecAngleH[1] = SpecH1;
	gSystemMgr.m_nSpecAngleV[0] = SpecV0;
	gSystemMgr.m_nSpecAngleV[1] = SpecV1;

	CString cstr;
	cstr.Format(L"%d", gSystemMgr.m_nFovTestFlag); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"FOVSetting", L"m_nFovTestFlag", cstr);
	cstr.Format(L"%.2f", gSystemMgr.m_dBsaicAngle); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"FOVSetting", L"m_dBsaicAngle", cstr);
	cstr.Format(L"%.2f", gSystemMgr.m_dBsaicAngle2); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"FOVSetting", L"m_dBsaicAngle2", cstr);
	cstr.Format(L"%.2f", gSystemMgr.m_dAddAngle); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"FOVSetting", L"m_dAddAngle", cstr);
	cstr.Format(L"%.2f", gSystemMgr.m_dAddAngle2); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"FOVSetting", L"m_dAddAngle2", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nFovBin[0]); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"FOVSetting", L"m_nFovBin[0]", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nFovBin[1]); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"FOVSetting", L"m_nFovBin[1]", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nFovBin[2]); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"FOVSetting", L"m_nFovBin[2]", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nFovBin[3]); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"FOVSetting", L"m_nFovBin[3]", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nPosPer[0]); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"FOVSetting", L"m_nPosPer[0]", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nPosPer[1]); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"FOVSetting", L"m_nPosPer[1]", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nPosW[0]); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"FOVSetting", L"m_nPosW[0]", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nPosW[1]); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"FOVSetting", L"m_nPosW[1]", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nPosH[0]); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"FOVSetting", L"m_nPosH[0]", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nPosH[1]); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"FOVSetting", L"m_nPosH[1]", cstr);
	cstr.Format(L"%.2f", gSystemMgr.m_nSpecAngleH[0]); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"FOVSetting", L"m_nSpecAngleH[0]", cstr);
	cstr.Format(L"%.2f", gSystemMgr.m_nSpecAngleH[1]); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"FOVSetting", L"m_nSpecAngleH[1]", cstr);
	cstr.Format(L"%.2f", gSystemMgr.m_nSpecAngleV[0]); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"FOVSetting", L"m_nSpecAngleV[0]", cstr);
	cstr.Format(L"%.2f", gSystemMgr.m_nSpecAngleV[1]); gSystemMgr.m_cCaptureConfigIni.SaveConfigIni(L"FOVSetting", L"m_nSpecAngleV[1]", cstr);

	gSystemLog.DisplayLogAndSave(L"FOV保存数据完成", LV_EVENT);
}


void CFovTestDlg::OnBnClickedButton1()
{
	SaveValueToConfig();
}


void CFovTestDlg::OnBnClickedCheck5()
{
	UpdateData(TRUE);
	gSystemMgr.m_bFovDisplayFlag = Display;
}


void CFovTestDlg::OnCbnSelchangeCombo2()
{
	gSystemMgr.m_nFovDisplayCnt = DisplayCnt.GetCurSel();
}
